package com.sky.controller.admin;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * PROJECT_NAME: sky-take-out
 * NAME: OrdersController
 * USER: zhang
 * DATE: 2023/5/31
 * DESCRIPTION :B端-订单信息表现层
 */
@Slf4j
@RestController("adminOrdersController")
@Api(tags = "B端-订单信息表现层")
@RequestMapping("admin/order")
public class OrdersController {
    @Resource
    private OrdersService ordersService;

    /**
     * 订单搜索
     * @param ordersPageQueryDTO 搜索条件参数
     * @return 全局通用返回信息Bean(总条数+OrderVO)
     */
    @ApiOperation("B端-商户订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> selectOrderByCondition(OrdersPageQueryDTO ordersPageQueryDTO){
         PageResult pageResult = ordersService.selectOrderByCondition(ordersPageQueryDTO);
         return Result.success(pageResult);
    }

    /**
     * 不同状态订单统计功能
     * @return 全局通用返回信息
     */
    @ApiOperation("B端-不同状态订单统计功能")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statisticsOrder(){
        OrderStatisticsVO orderStatisticsVO = ordersService.statisticsOrder();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 查询订单详情
     * @param orderId 订单Id
     * @return 全局通用返回信息Bean(订单信息+订单详情)
     */
    @ApiOperation("B端-查询订单详情")
    @GetMapping("/details/{orderId}")
    public Result<OrderVO> selectOrderVO(@PathVariable Long orderId){
        OrderVO orderVO = ordersService.selectOrderVO(orderId);
        return Result.success(orderVO);
    }

    /**
     * 接单
     * @param orders 订单基本信息(订单Id)
     * @return 全局通用返回信息Bean
     */
    @ApiOperation("B端-接单")
    @PutMapping("/confirm")
    public Result confirmOrder(@RequestBody Orders orders){
        ordersService.confirmOrder(orders);
        return Result.success();
    }

    /**
     * 拒单
     * @param ordersRejectionDTO 拒绝订单DTO(订单Id+拒单原因)
     * @return 全局通用返回信息Bean
     */
    @ApiOperation("B端-拒单")
    @PutMapping("/rejection")
    public Result rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        ordersService.rejectionOrder(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 商家取消订单
     * @param orders 要取消的订单Id和订单取消原因
     * @return  全局通用返回信息Bean
     */
    @ApiOperation("B端-取消订单")
    @PutMapping("/cancel")
    public Result cancelOrder(@RequestBody Orders orders){
        ordersService.adminCancelOrder(orders);
        return Result.success();
    }

    /**
     * 派送订单
     * @param orderId 要派送的订单Id
     * @return 全局通用返回信息Bean
     */
    @ApiOperation("B端-派送订单")
    @PutMapping("/delivery/{orderId}")
    public Result deliveryOrder(@PathVariable Long orderId){
        ordersService.deliveryOrder(orderId);
        return Result.success();
    }

    /**
     * 完成订单
     * @param orderId 要完成订单Id
     * @return 全局通用返回信息Bean
     */
    @ApiOperation("B端-完成订单")
    @PutMapping("/complete/{orderId}")
    public Result completeOrder(@PathVariable Long orderId){
        ordersService.completeOrder(orderId);
        return Result.success();
    }
}
